const app = getApp();
const { htmlDecode} = require('../../utils/util.js')

const api = app.apiInstance;

Page({
  /**
   * 页面的初始数据
   */
  data: {
    fileUrl: app.globalData.fileUrl,
    risks: [],
    sapId: null,
    myName: null,
    dealFlag: 1,
    nodeArray: ['申请退回', '指派责任部门', '指派处理', '隐患排除中', '整改后审核', '闭环'],
    flowTypeArray: ['指派责任部门','指派整改人','整改隐患','整改后审核','延期审核','提出隐患','申请延期'],
    nodeIndex: '',
    baseUrl: app.globalData.baseUrl,
    illegalList:[],
    x:10, //添加的拖拽X轴
    y:400 //添加的拖拽Y轴
  },

  addTouchStart:function(e) {
    
    this.startX = e.touches[0].pageX;
    this.startY = e.touches[0].pageY;
  },
  addTouchMove:function(e) {
    const moveX = e.touches[0].pageX;
    const moveY = e.touches[0].pageY;
    const dx = moveX - this.startX;
    const dy = moveY - this.startY;
 
    this.setData({
      x: this.data.x + dx,
      y: this.data.y + dy
    });
 
    this.startX = moveX;
    this.startY = moveY;
  },

  initSapId: function(){
    var userInfo = wx.getStorageSync('userinfo');
    console.log('userInfo',userInfo);
    this.setData({
      sapId: userInfo.siocSapNo,
      myName: userInfo.siocCnName
    })
  },
  nodeChange(e){
    this.setData({
      nodeIndex: e.detail.value
    });
    this.getMyIllegal();
  },
  nodeCancel(){
    this.setData({
      nodeIndex: ''
    });
    this.getMyIllegal();
  },
  getMyIllegal: function () {
    var that = this;

    api.get('/illegalRecord/wx/getMyIllegal',{node:that.data.nodeIndex}).then(res=>{
      const data = res;
      data.rows.forEach(item=>{
        item.content = htmlDecode(item.content)
        item.location = htmlDecode(item.location)
        item.suggest = htmlDecode(item.suggest)
      })

      that.setData({
        illegalList: data.rows,
        dealFlag: 1
      })
    })

   
  },
  getMyAuditIllegal: function (e) {
    var tempDealFlag = e.currentTarget.dataset.operation;
    this.getAuditRisk(tempDealFlag);
  },

  getAuditRisk(tempDealFlag){
    var that = this;

    api.get('/illegalRecord/wx/getMyAuditIllegal',{dealFlag:tempDealFlag}).then(res=>{
      const data = res;
      that.setData({
        illegalList: data.rows,
        dealFlag: tempDealFlag
      })
    })

  
  },
  goAdd(){
    wx.navigateTo({
      url: '/pages/illegal-staff/illegal-staff',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.initSapId();
    this.getAuditRisk(2);
    this.startX = 0;
    this.startY = 0;
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})